<?php
function introtext_show($introtext){
	return preg_replace("/<img[^>]+\>/i", "", $introtext);
}

function getImage($num,$content) {
global $more;
$more = 1;

$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);;
$image[$i] = $postOutput;
$start=$imgEnd+1;
}
preg_match('/<img.+?src(?: )*=(?: )*[\'"](.*?)[\'"]/si', $image[$num], $arrResult);

//print_r($arrResult[1]);exit;
return $arrResult[1];
//return stristr($image[$num],'<img>');
}

function catch_that_image($content) {
		  $first_img = '';
		  ob_start();
		  ob_end_clean();
		  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
		  $first_img = $matches [1] [0];
		
		  if(empty($first_img)){ //Defines a default image
			$first_img = "images/noimage.gif";
		  }
		  return $first_img;
}

function cutnchar($str,$n)
{
	if(strlen($str)<$n) return $str;
	$html    = substr($str,0,$n);
	$html    = substr($html,0,strrpos($html,' '));
	return $html.'...';
}
function trim_text($input, $length, $ellipses = true, $strip_html = true) {
	//strip tags, if desired
	if ($strip_html) {
		$input = strip_tags($input);
	}

	//no need to trim, already shorter than trim length
	if (strlen($input) <= $length) {
		return $input;
	}

	//find last space within length
	$last_space = strrpos(substr($input, 0, $length), ' ');
	$trimmed_text = substr($input, 0, $last_space);

	//add ellipses (...)
	if ($ellipses) {
		$trimmed_text .= '...';
	}

	return $trimmed_text;
}